Intrinsic: binaryen.removable.if.unused#8268
Conversation
|
Regarding the name: do the semantics match any of the existing GCC attributes of |
|
@dschuff Sadly I don't think they match those. gcc's Concretely, this is valid in gcc: x = pure();
foo();
bar(x);
=>
foo();
bar(pure()); // pure function pushed past foo(), which it cannot interact withBut that is not valid if |
|
Maybe |
|
@tlively I think more than removability is possible, though. The full meaning is "has no effects if the value is not used". Perhaps To clarify what I mean by more than removability being possible: imagine some code cannot be removed for technical, type-system or IR structure reasons. It might still be useful to know it has no effects. Not a great example, but: (drop
(block $block (result (ref $A))
(br_if $block
(local.get $value)
(local.get $condition)
)
(call $dead.if.unused)
)
)
(call $foo)The |
|
IIUC, we cannot move it past the |
|
Ah, do you mean because the call might trap or throw? Fair enough. So amend my example to replace |
|
No, we couldn't move a call with this annotation past a |
|
Ok, after discussion offline I agree @tlively 's approach is better here. So I think renaming to This also means that the optimization in this PR is the only thing the intrinsic allows: literally removing it from its current position, in Vacuum, and nothing else. |
|
Updated to the final name |
Co-authored-by: Thomas Lively <tlively123@gmail.com>
Co-authored-by: Thomas Lively <tlively123@gmail.com>
Based on discussion in
#7574 (comment)
the
@binaryen.removable.if.unusedcode annotation has the meaning thatif the result is unused (dropped), then the code can be considered
dead (no side effects, removable).
This can be used on a function to affect all calls to it, or on specific
call instructions. The optimizer then finds relevant dropped calls and
can remove them (in Vacuum).
Bikeshedding welcome on the name.
edit: updated, original name was
dead.if.unused